<?php
ob_start(); // ให้ใช้ Header ได้
session_start();
include("include/config.inc.php");
include("include/function.php");
include("include/class.mysql.php");
mysql_select_db($db) ;
//error_reporting (0); 
if($_SESSION['varEmpty'] == "") // เปลี่ยนค่าครั้งแรกให้เป็น 0 เพื่อไว้ใช้ตอนทำ array
{
		$_SESSION['varEmpty'] = 0;
}

if($_SESSION['sendPrice'] == "") // เปลี่ยนค่าครั้งแรกให้เป็น 0 เพื่อไว้ใช้ตอนทำ array
{
		$_SESSION['sendPrice'] = 0;
}

if($_SESSION['pcount'] == "") // เปลี่ยนค่าครั้งแรกให้เป็น 0 เพื่อไว้ใช้ตอนทำ array
{
		$_SESSION['pcount'] = 0;
}

$_SESSION['sum_subtotal'] = 0; //ประกาศค่าคงที่

$_SESSION['total'] = 0; //ประกาศค่าคงที่
$_SESSION['vat'] = 0; //ประกาศค่าคงที่
//session_destroy();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-874" />
<script type="text/javascript" src="include/java.js"></script>
<script type="text/javascript" src="include/checkForm.js"></script>
<SCRIPT language=JavaScript src="include/hotmail___1025000104.js"></SCRIPT>
<SCRIPT LANGUAGE="JavaScript" SRC="include/CalendarPopup.js"></SCRIPT>
<SCRIPT LANGUAGE="JavaScript">
		var cal = new CalendarPopup();
</SCRIPT>
<title>OlizaPro ยินดีต้อนรับ</title>

<link href="default.css" rel="stylesheet" type="text/css">
<style type="text/css">
<!--
body {
	margin-left: 0px;
	margin-top: 0px;
	margin-right: 0px;
	margin-bottom: 0px;
	background-color: #3F341E;
}
-->
</style>
<!-- LightBox -->
<link rel="stylesheet" href="css/lightbox.css" type="text/css" media="screen" />
	<script src="js/prototype.js" type="text/javascript"></script>
	<script src="js/scriptaculous.js?load=effects,builder" type="text/javascript"></script>
	<script src="js/lightbox.js" type="text/javascript"></script>
<!-- LightBox -->
<style type="text/css">
<!--
body,td,th {
	font-family: Peach TV;
}
.style17 {
	color: #FFFFFF;
	font-family: "Peach TV";
	font-size: 14;
}
.style20 {
	color: #000000
}
.style21 {color: #FFFFFF}
.style22 {
	color: #FFFFFF;
	font-size: 16;
}
.style59 {font-size: medium;
	font-family: "TH Charmonman";
}
.style60 {font-size: x-large;
	font-family: "Peach TV";
}
.style67 {font-family: "Peach TV"}
.style68 {	font-size: xx-large;
	font-family: "Peach TV";
}
.style70 {font-size: x-large}
.style71 {font-size: xx-large}
#apDiv6 {
	position:absolute;
	left:201px;
	top:379px;
	width:861px;
	height:778px;
	z-index:5;
	background-color: #BFA711;
}
.style66 {
	font-size: x-large;
	font-family: "Peach TV";
}
-->
</style>
</head>
<script type="text/javascript" src="ajax/board.js"></script>
<body onload="doAdd('1','')">
<table width="1035" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td width="130" height="175" valign="top" background="images/online3_01.gif"><table width="100%" height="179" border="0" cellpadding="0" cellspacing="0">
      <tr>
        <td height="71" colspan="2">&nbsp;</td>
      </tr>
      <tr>
        <td width="8%" height="108" valign="top">&nbsp;</td>
        <td width="92%" valign="top"><?
	if(isset($_SESSION['login_true_member'])) // ถ้า login สำเร็จ
	{
	?>
          <span class="defaultFont"><span class="style21"><strong>Login :</strong></span>
          <?=$_SESSION['login_true_member']?>
          </span><br />
          <br />
          <table width="100%" border="0" cellspacing="0" cellpadding="0">
            <tr>
              <td><span class="style21">-</span> <a href="./?module=member&amp;action=editForm" class="style22" id="login">แก้ไขข้อมูลสมาชิก</a><br />
                <span class="style21">-</span> <a href="./?module=member&amp;action=history" class="style21" id="login">ประวัติการสั่งซื้อ</a></td>
            </tr>
          </table>
          <span class="style21">-</span> <a href="./?module=logout" id="login"> ออกจากระบบ</a>
          <?
	}
	else
	{
	?>
          <div align="center"></div>
          <form id="form2" name="form2" method="post" action="./?module=login" style="padding: 0px; margin: 0px;">
            <table width="100%" height="131" border="0" cellpadding="0" cellspacing="0">
              <tr>
                <td><span class="defaultFont style21">Username : </span></td>
              </tr>
              <tr>
                <td height="22"><input name="user_login" type="text" id="user_login" size="15" /></td>
              </tr>
              <tr>
                <td height="13"><span class="defaultFont style21">Password : </span></td>
              </tr>
              <tr>
                <td><input name="pwd_login" type="password" id="pwd_login" size="15" /></td>
              </tr>
              <tr>
                <td><span class="style21">
                  <input name="btnLogin" type="submit" id="btnLogin" value="Login" />
                  <input name="Reset" type="reset" id="Reset" value="Clear" />
                </span></td>
              </tr>
            </table>
            <?
}
			?>
          </form></td>
      </tr>
    </table></td>
    <td width="936" valign="top" background="images/bar_1_test.jpg"><table width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td height="33" valign="bottom">&nbsp;</td>
      </tr>
    </table></td>
  </tr>
</table>
<table width="1034" height="44" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#281C06">
  <tr>
    <td width="129" height="44" bgcolor="#281C06"><img src="images/online3_04.gif" width="129" height="27" alt="" /></td>
    <td width="905" background="images/online3_05.gif"><table width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td bgcolor="#281C06"> &nbsp;<span class="style17"> 
          <? if(!isset($_SESSION[login_true_member])) { ?>
          <a href="./?module=register" id="topMenu">สมัครสมาชิก</a> |<a href="board.php" id="topMenu"> เว็บบอร์ด</a> |</span> <span class="style17"><a href="./?module=forgotpass" id="topMenu">ลืมรหัสผ่าน</a> |</span>
          <span class="style17">
          <? } ?>
          <a href="./?module=index" id="topMenu">หน้าร้าน</a> | <a href="advise.php" id="topMenu"> ให้คำปรึกษาผลิตภัณฑ์</a> | </span> <span class="style17"><a href="./admin/" id="topMenu">ผู้ดูแลระบบ</a></span></td>
      </tr>
    </table>
      <table width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td width="73%" height="25" bgcolor="#FFFFCC"><form id="form1" name="form1" method="post" action="./?module=search" style="padding: 0px; margin: 0px;"  onsubmit="return chk_search(this)">
  &nbsp;<img src="images/Search.png" width="28" height="24" /><span class="defaultFont"><span class="style20">ค้นหา :</span>&nbsp;
  <input name="txtSearch" type="text" id="txtSearch" size="10" />
  &nbsp;จาก&nbsp;
  <select name="searchBy" id="searchBy">
    <option value="ชื่อสินค้า">ชื่อสินค้า</option>
    <option value="รหัสสินค้า">รหัสสินค้า</option>
    <option value="ราคาสินค้า">ราคาสินค้า</option>
  </select>
  </span>
        <input type="submit" name="Submit" value="ค้นหา" />
        </form></td>
        <td width="27%"><table width="100%" height="32" border="0" cellpadding="0" cellspacing="0">
          <tr>
            <td width="79%" bgcolor="#FFFFCC"><div align="right"><span class="defaultFont"><a href="./?module=cart"><img src="images/cart_b.gif" width="85" height="25" border="0" /></a></span></div></td>
            <td width="21%" bgcolor="#FFFFCC"><span class="defaultFont"><strong> :
              <?=$_SESSION['varEmpty']?>
            </strong></span></td>
          </tr>
        </table></td>
      </tr>
    </table></td>
  </tr>
</table>
<table width="1034" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td width="129" height="357" valign="top" background="images/online3_12.gif"><table width="100%" height="140" border="0" cellpadding="0" cellspacing="0">
      <tr>
        <td height="140" valign="top" bgcolor="#281C06"><br />
          <table width="100%" border="0" cellpadding="0" cellspacing="0" bgcolor="#281C06">
            <tr>
              <td width="17%" height="124">&nbsp;</td>
              <td width="83%"><img src="images/bulet_orange.gif" width="13" height="9" /><span class="style20"><a href="./?module=product&amp;action=new" id="catMenu">สินค้าใหม่</a> <img src="images/new.gif" width="25" height="11" /><br />
                  <img src="images/bulet_orange.gif" width="13" height="9" /><a href="./?module=product&amp;action=hot" id="catMenu">สินค้าขายดี</a><img src="images/hot.gif" width="23" height="11" /><br />
                  <img src="images/bulet_orange.gif" width="13" height="9" /><a href="./?module=product&amp;action=all" id="catMenu">ดูสินค้าทั้งหมด</a></span><br />
                  <hr />

                  <table width="100%" border="0" cellspacing="0" cellpadding="0">
                  
                  
                  
                    <?
$sqlCat = "select * from tb_category  order by c_id "; 
$resultCat = mysql_db_query($db,$sqlCat);
$NRowCat = mysql_num_rows($resultCat);
while ($rowCat = mysql_fetch_array($resultCat)) { 

			 $c_name = $rowCat["c_name"];
			 $c_id = $rowCat["c_id"];


						  ?>
			        <tr>
                      <td height="20"><img src="images/bulet_orange.gif" width="13" height="9" /><a href="./?module=product&amp;category=<?=$c_id?>" id="catMenu">
                      <?=$c_name?>
                      </a> </td>
                    </tr>  <? } ?>
                  </table>
                <img src="images/spacer.gif" width="1" height="5" /></td>
            </tr>
          </table>
          </td>
      </tr>
    </table>
      <img src="images/spacer.gif" width="1" height="1" /><br />

      <table width="100%" border="0" cellspacing="0" cellpadding="0">
        <tr>
          <td><img src="images/online_16.gif" alt="" width="129" height="28" /><br /></td>
        </tr>
      </table>
      <table width="100%" border="0" cellspacing="0" cellpadding="0">
        <tr>
          <td height="148" valign="top" background="images/online3_12.gif"><table width="100%" border="0" cellspacing="0" cellpadding="0">
            <tr>
              <td width="16%" height="154" bgcolor="#281C06">&nbsp;</td>
              <td width="84%"><table width="100%" height="152" border="0" cellpadding="0" cellspacing="0">
                  <tr>
                    <td height="19" bgcolor="#281C06"><span class="fontWhite"><img src="images/bulet_green.gif" width="13" height="9" /><a href="./?module=index" id="catMenu">หน้าแรก</a></span></td>
                  </tr>
                  
              <? if(!isset($_SESSION[login_true_member])) {?>
			      <tr>
                    <td height="19" bgcolor="#281C06"><span class="fontWhite"><img src="images/bulet_green.gif" width="13" height="9" /><a href="./?module=register" id="catMenu">สมัครสมาชิก</a></span></td>
                  </tr>
				  <? } ?>
                  <tr>
                    <td height="19" bgcolor="#281C06"><span class="fontWhite"><img src="images/bulet_green.gif" width="13" height="9" /><a href="./?module=pay" id="catMenu">แจ้งชำระเงิน</a></span></td>
                  </tr>
                  <tr>
                    <td height="19" bgcolor="#281C06"><span class="fontWhite"><img src="images/bulet_green.gif" width="13" height="9" /><a href="./?module=other&amp;action=how2buy" id="catMenu">วิธีการสั่งซื้อ</a></span></td>
                  </tr>
                  <tr>
                    <td height="19" bgcolor="#281C06"><span class="fontWhite"><img src="images/bulet_green.gif" width="13" height="9" /><a href="./?module=other&amp;action=how2pay" id="catMenu">วิธีการชำระเงิน</a></span></td>
                  </tr>
                  <tr>
                    <td height="19" bgcolor="#281C06"><span class="fontWhite"><img src="images/bulet_green.gif" width="13" height="9" /><a href="./?module=contactus" id="catMenu">ติดต่อเรา</a></span></td>
                  </tr>
                  <tr>
                    <td height="19" bgcolor="#281C06"><p class="fontWhite"><img src="images/bulet_green.gif" width="13" height="9" /><a href="./?module=other&amp;action=aboutus" id="catMenu">เกี่ยวกับเรา</a></p>
                      <p class="fontWhite">&nbsp;</p></td>
                  </tr>
              </table></td>
            </tr>
          </table></td>
        </tr>
    </table>
    </td>
    <td width="905" valign="top" background="images/online_bg_table_main.gif" bgcolor="#BFA711"><div align="center">
      <p class="style66">ผลิตภัณฑ์ที่มีความเหมาะสมกับท่าน</p>
      <p class="style66">
        <?php 
		require_once('Connections/conn.php');
        mysql_select_db($database_conn, $conn);

  $fileHandler = fopen("C:\AppServ\www\oliza\cluster.csv", "w"); //กำหนดไฟล์ .cvs เพื่อรับค่าที่ได้มาจาก weka
  chdir("C:\Program Files\Weka-3-6"); //เปลี่ยนไปยังตำแหน่งที่weka ติดตั้งชั่วคราว
  $cmd='java  -cp  weka.jar weka.clusterers.SimpleKMeans  -N 5 -t  "C:\AppServ\www\oliza\weka\cluster.arff"'; //สั่งให้ weka ประมวลผลข้อมูลให้อัตโนมัติ
  exec($cmd,$output) ; //ประมวลคำสั่งให้ weka ประมวลผลอัตโนมัติและเก็บค่าที่ได้จาก weka ส่งออกมาให้เก็บไว้ที่ตัวแปร array ชื่อ output
  for($i=0;$i < sizeof($output);$i++){
	  
	  fputcsv($fileHandler, split(' ',trim($output[$i])));//เขียนข้อมูลลงไฟล์ cluster.cvs
  }
  // ปิดไฟล์
	fclose($fileHandler);
  //เก็บลงฐานข้อมูล

  $fp = fopen("C:\AppServ\www\oliza\cluster.csv", "rw"); //อ่านค่าจากไฟล์ CSV แบบอ่านและเขียน
if ($fp) { //ตรวจสอบว่าเปิดไฟลืได้หรือไม่ถ้าได้ให้ทำงานต่อไป
	$txtAr = array();//ประกาศตัวแปรอาเรย์เพื่อเก็บค่าที่ได้จากไฟล์ csv 
	$rowsAr = array();//ประกาศตัวแปรอาเรย์เพื่อเก็บค่าที่ได้ตัดเป็นช่วงข้อมูลจากอาเรย์ $txtAr
	$i=1; //ประกาศตัวแปร i เพื่ออ่านแถวเฉพาะข้อมูลที่ต้องการ
	while (!feof($fp)) { 
		$file = fgets($fp, 4096); //อ่านค่ามาที่ละบรรทัด ไม่เกิน 2 กิโลไบต์
		$i++; //บวกค่าที่ละหนึ่ง
		if($i>=15 and $i<=36){ //เริ่มอ่านจากแถวที่ 15 ถึงแถวที่ 36
			$file=$file.","; //อ่านจากตัวแปร
			
			 $fileStrArr = str_split($file);//อ่านค่ามาเป็นอาเรย์

			$j=1; //กำหนดค่าตัวแปล j เพื่อเช็คว่าเจอตัวอักษรหรือคอมม่า
			foreach($fileStrArr as $v) //วนอ่านค่าจากอาเรย์มาที่ละตัว
			{
				if($v!=',' ) {//ถ้าไม่เท่ากับคอมม่าให้เอามาเก็บไว้ที่อาเรย์
					$j=1;
					$txtM  .= $v;
				}
				else {//ถ้าเจอคอมม่าให้ถ่ายค่าข้อมูลไปเก็บที่ตัวแปลอาเรย์อีกตัว
					if($j==1){//
						$txtAr[] =$txtM;
						$txtM = '';//กำหนดตัวแปรให้ว่างเพื่อรับค่าต่อไป
					}
					$j++;
				}
			}
			$rowsAr[] =  $txtAr;//กำหนค่าแต่ละแถวที่ได้ให้ต้วแปรอาเรย์อีกตัวเพื่อจะไปเก็บในฐานข้อมูล
	}
}

$query = "TRUNCATE TABLE clusterf_model_assoc"; //เคลียร์ข้อมูลเก่าทิ้งก่อน
$result = mysql_query($query, $conn) or die(mysql_error()); //เคลียร์ข้อมูลทิ้งก่อน

foreach($rowsAr as $content=>$value){ //วนรอบอ่านค่าจากข้อมูลเพื่อเก็บค้าลงฐานข้อมูล
	if($content==21){
/*			$query = "INSERT INTO clusterf_model_assoc";
			$query=$query." VALUES (0,'{$rowsAr[21][1]}','{$rowsAr[21][8]}', '{$rowsAr[21][15]}', '{$rowsAr[21][22]}',";
			$query=$query."'{$rowsAr[21][29]}',  '{$rowsAr[21][36]}',  '{$rowsAr[21][43]}',  '{$rowsAr[21][50]}', '{$rowsAr[21][57]}',";
			$query=$query."'{$rowsAr[21][64]}',  '{$rowsAr[21][71]}',  '{$rowsAr[21][78]}',  '{$rowsAr[21][85]}',";
			$query=$query."'{$rowsAr[21][92]}', '{$rowsAr[21][99]}',  '{$rowsAr[21][106]}',  '{$rowsAr[21][113]}',  '{$rowsAr[21][120]}',";
			$query=$query."'{$rowsAr[21][127]}', '{$rowsAr[21][134]}', '{$rowsAr[21][141]}', '{$rowsAr[21][148]}')";
			$result = mysql_query($query, $conn) or die(mysql_error()); */
			$query = "INSERT INTO clusterf_model_assoc";
			$query=$query." VALUES (0,'{$rowsAr[21][2]}','{$rowsAr[21][9]}', '{$rowsAr[21][16]}', '{$rowsAr[21][23]}',";
			$query=$query."'{$rowsAr[21][30]}',  '{$rowsAr[21][37]}',  '{$rowsAr[21][44]}',  '{$rowsAr[21][51]}', '{$rowsAr[21][58]}',";
			$query=$query."'{$rowsAr[21][65]}',  '{$rowsAr[21][72]}',  '{$rowsAr[21][79]}',  '{$rowsAr[21][86]}',";
			$query=$query."'{$rowsAr[21][93]}', '{$rowsAr[21][100]}',  '{$rowsAr[21][107]}',  '{$rowsAr[21][114]}',  '{$rowsAr[21][121]}',";
			$query=$query."'{$rowsAr[21][128]}', '{$rowsAr[21][135]}', '{$rowsAr[21][142]}', '{$rowsAr[21][149]}')";
			$result = mysql_query($query, $conn) or die(mysql_error());
			$query = "INSERT INTO clusterf_model_assoc";
			$query=$query." VALUES (0,'{$rowsAr[21][3]}','{$rowsAr[21][10]}', '{$rowsAr[21][17]}', '{$rowsAr[21][24]}',";
			$query=$query."'{$rowsAr[21][31]}',  '{$rowsAr[21][38]}',  '{$rowsAr[21][45]}',  '{$rowsAr[21][52]}', '{$rowsAr[21][59]}',";
			$query=$query."'{$rowsAr[21][66]}',  '{$rowsAr[21][73]}',  '{$rowsAr[21][80]}',  '{$rowsAr[21][87]}',";
			$query=$query."'{$rowsAr[21][94]}', '{$rowsAr[21][101]}',  '{$rowsAr[21][108]}',  '{$rowsAr[21][115]}',  '{$rowsAr[21][122]}',";
			$query=$query."'{$rowsAr[21][129]}', '{$rowsAr[21][136]}', '{$rowsAr[21][143]}', '{$rowsAr[21][150]}')";
			$result = mysql_query($query, $conn) or die(mysql_error());
			$query = "INSERT INTO clusterf_model_assoc";
			$query=$query." VALUES (0,'{$rowsAr[21][4]}','{$rowsAr[21][11]}', '{$rowsAr[21][18]}', '{$rowsAr[21][25]}',";
			$query=$query."'{$rowsAr[21][32]}',  '{$rowsAr[21][39]}',  '{$rowsAr[21][46]}',  '{$rowsAr[21][53]}', '{$rowsAr[21][60]}',";
			$query=$query."'{$rowsAr[21][67]}',  '{$rowsAr[21][74]}',  '{$rowsAr[21][81]}',  '{$rowsAr[21][88]}',";
			$query=$query."'{$rowsAr[21][95]}', '{$rowsAr[21][102]}',  '{$rowsAr[21][109]}',  '{$rowsAr[21][116]}',  '{$rowsAr[21][123]}',";
			$query=$query."'{$rowsAr[21][130]}', '{$rowsAr[21][137]}', '{$rowsAr[21][144]}', '{$rowsAr[21][151]}')";
			$result = mysql_query($query, $conn) or die(mysql_error());
			$query = "INSERT INTO clusterf_model_assoc";
			$query=$query." VALUES (0,'{$rowsAr[21][5]}','{$rowsAr[21][12]}', '{$rowsAr[21][19]}', '{$rowsAr[21][26]}',";
			$query=$query."'{$rowsAr[21][33]}',  '{$rowsAr[21][40]}',  '{$rowsAr[21][47]}',  '{$rowsAr[21][54]}', '{$rowsAr[21][61]}',";
			$query=$query."'{$rowsAr[21][68]}',  '{$rowsAr[21][75]}',  '{$rowsAr[21][82]}',  '{$rowsAr[21][89]}',";
			$query=$query."'{$rowsAr[21][96]}', '{$rowsAr[21][103]}',  '{$rowsAr[21][110]}',  '{$rowsAr[21][117]}',  '{$rowsAr[21][124]}',";
			$query=$query."'{$rowsAr[21][131]}', '{$rowsAr[21][138]}', '{$rowsAr[21][145]}', '{$rowsAr[21][152]}')";
			$result = mysql_query($query, $conn) or die(mysql_error());
			$query = "INSERT INTO clusterf_model_assoc";
			$query=$query." VALUES (0,'{$rowsAr[21][6]}','{$rowsAr[21][13]}', '{$rowsAr[21][20]}', '{$rowsAr[21][27]}',";
			$query=$query."'{$rowsAr[21][34]}',  '{$rowsAr[21][41]}',  '{$rowsAr[21][48]}',  '{$rowsAr[21][55]}', '{$rowsAr[21][62]}',";
			$query=$query."'{$rowsAr[21][69]}',  '{$rowsAr[21][76]}',  '{$rowsAr[21][83]}',  '{$rowsAr[21][90]}',";
			$query=$query."'{$rowsAr[21][97]}', '{$rowsAr[21][104]}',  '{$rowsAr[21][111]}',  '{$rowsAr[21][118]}',  '{$rowsAr[21][125]}',";
			$query=$query."'{$rowsAr[21][132]}', '{$rowsAr[21][139]}', '{$rowsAr[21][146]}', '{$rowsAr[21][153]}')";
			$result = mysql_query($query, $conn) or die(mysql_error());
	}
}
fclose($fp);
}
//สิ้นสุด

//ประมวล Association
$fileHandler2 = fopen("C:\AppServ\www\oliza\association.csv", "w");
  chdir("C:\Program Files\Weka-3-6");
  $cmd2='java  -cp  weka.jar weka.associations.Apriori  -N 15 -T 0 -C 0.9 -D 0.05 -U 1.0 -M 0.1 -S -1.0 -c -1 -t "C:\AppServ\www\oliza\weka\association3.arff"';
  exec($cmd2,$output2) ;
  for($i=0;$i< sizeof($output2);$i++){
	  
	  fwrite($fileHandler2, trim($output2[$i])."\n");//เขียนข้อมูลลงไฟล์ 
  }
 
	fclose($fileHandler2);

chdir("C:\AppServ\www\oliza");
$query = "TRUNCATE TABLE association";
$result = mysql_query($query, $conn) or die(mysql_error());//เคลียร์ข้อมูลทิ้งก่อน
$association = file('association.csv');
$sh="1. FLotion";$sh2="2. BDSalt=Yes";$sh3="3. FLotion=Yes";$sh4="4. FLotion=Yes";$sh5="5. FGel=Yes";
$sh6="6. FLotion";$sh7="7. FClone=Yes";$sh8="8. BDClone=Yes";$sh9="9. FClone=Yes";$sh10="10. BDSalt=Yes";$sh11="11. BDMilk=Yes";
$sh12="12. BDCream=Yes";$sh13="13. FToner=Yes";$sh14="14. FLotion=Yes";
foreach($association as $data)//อ่านค่าออกมาที่ละแถว
{
	//ดึงเอาเฉพาะข้อมูลที่เป็นผลมาเพิ่มในตาราง association
   if(strpos($data,$sh) !==false || strpos($data,$sh2) !==false || strpos($data,$sh3) !==false || strpos($data,$sh4) !==false || strpos($data,$sh5) !==false  || strpos($data,$sh6) !==false || strpos($data,$sh7) !==false || strpos($data,$sh8) !==false || strpos($data,$sh9) !==false || strpos($data,$sh10) !==false || strpos($data,$sh11) !==false || strpos($data,$sh12) !==false || strpos($data,$sh13) !==false || strpos($data,$sh14) !==false){
		$datarow = explode(' ', trim($data));
		$query = "INSERT INTO association";
		$query=$query." VALUES (0,'$datarow[0]','$datarow[1]','$datarow[2]','$datarow[3]','$datarow[4]','$datarow[5]','$datarow[6]','$datarow[7]','$datarow[8]','$datarow[9]')";
		$result = mysql_query($query, $conn) or die(mysql_error());
   }
}
//รับค่าจากฟอร์ม advise.php
	$Sex=trim($_POST['Sex']);
	$Age=trim($_POST['Age']);
	$SkinID=trim($_POST['SkinID']);
	$Noallergy=trim($_POST['Noallergy']); //ไม่เคยแพ้ใช้ได้ทุกประเภท
	$Foamallergy=trim($_POST['Foamallergy']); //แพ้โฟมหน้า ใช้แล้วเป็นสิวหรือผดผื่นคัน
	$Creamallergy=trim($_POST['Creamallergy']); //แพ้ครีมบำรุง ใช้แล้วเป็นสิวหรือผดผื่นคัน
	$Sunblockallergy=trim($_POST['Sunblockallergy']);  //แพ้ครีมกันแดด
	$Perfumeallergy=trim($_POST['Perfumeallergy']); // แพ้ผลิตภัณฑ์ที่มีส่วนผสมของน้ำหอม สีและสารกันเสีย
	
	$Acneonface=trim($_POST['Acneonface']); //ปัญหาสิวบนใบหน้า
	$Pimple=trim($_POST['Pimple']);  //ปัญหาสิวเสี้ยน
	$Pores=trim($_POST['Pores']); //ปัญหารูขุมขนกว้าง
	$Melasma=trim($_POST['Melasma']); //ปัญหากระ ฝ้า
	$SkincolornotRegularly=trim($_POST['SkincolornotRegularly']); //ปัญหาใบหน้าหมองคล้ำ สีผิวไม่สม่ำเสมอ
	$Wrinkle=trim($_POST['Wrinkle']); //ปัญหาริ้วรอยบนใบหน้า
	$bodycolornotRegularly=trim($_POST['bodycolornotRegularly']); //ปัญหาสิวบนลำตัว เช่น หลัง หน้าอก
	$Acneonbody=trim($_POST['Acneonbody']); //ปัญหาสิวกายหมองคล้ำ จุดด่างดำ สีผิวไม่สม่ำเสมอ
	$HandFoot=trim($_POST['HandFoot']); //ปัญหามือ เท้า หยาบ กระด้าง

	//ส่วนต่อไปนำเงื่อนที่ลูกค้าส่งมาวิเคราะห์กับ Data Mining ที่กำหนดไว้ใน cluster.arff ที่นำเข้ามาที่ตารางข้อมูล
	$sqlCmd="SELECT * FROM clusterf_model_assoc";
	$sqlCmd=$sqlCmd." WHERE (Sex='$Sex')";
	$sqlCmd=$sqlCmd." AND (Age='$Age')";
	$sqlCmd=$sqlCmd." AND (SkinID='$SkinID')";
	$sqlCmd=$sqlCmd." AND  (Allergy='$Noallergy' OR Allergy='$Foamallergy' OR Allergy='$Creamallergy' OR";
	$sqlCmd=$sqlCmd." Allergy='$Sunblockallergy' OR Allergy='$Peffunmeallergy' OR Allergy2='$Noallergy' OR";
	$sqlCmd=$sqlCmd." Allergy2='$Foamallergy' OR Allergy2='$Creamallergy' OR Allergy2='$Sunblockallergy' OR"; 
	$sqlCmd=$sqlCmd." Allergy2='$Peffunmeallergy'  OR   Allergy3='$Noallergy' OR Allergy3='$Foamallergy' OR";
	$sqlCmd=$sqlCmd." Allergy3='$Creamallergy' OR Allergy3='$Sunblockallergy' OR Allergy3='$Peffunmeallergy')";
	$sqlCmd=$sqlCmd." AND (Prob_Skin1='$Acneonface' OR  Prob_Skin1='$Pimple' OR Prob_Skin1='$Pores' OR";
	$sqlCmd=$sqlCmd." Prob_Skin1='$Melasma' OR Prob_Skin1='$SkincolornotRegularly' OR Prob_Skin1='$Wrinkle' OR";
	$sqlCmd=$sqlCmd." Prob_Skin1='$bodycolornotRegularly' OR Prob_Skin1='$Acneonbody' OR Prob_Skin1='$HandFoot' OR";
	$sqlCmd=$sqlCmd." Prob_Skin2='$Acneonface' OR  Prob_Skin2='$Pimple' OR Prob_Skin2='$Pores' OR";
	$sqlCmd=$sqlCmd." Prob_Skin2='$Melasma' OR Prob_Skin2='$SkincolornotRegularly' OR Prob_Skin2='$Wrinkle' OR";
	$sqlCmd=$sqlCmd." Prob_Skin2='$bodycolornotRegularly' OR Prob_Skin2='$Acneonbody' OR Prob_Skin2='$HandFoot' OR";
	$sqlCmd=$sqlCmd." Prob_Skin3='$Acneonface' OR  Prob_Skin3='$Pimple' OR Prob_Skin3='$Pores' OR";
	$sqlCmd=$sqlCmd." Prob_Skin3='$Melasma' OR Prob_Skin3='$SkincolornotRegularly' OR Prob_Skin3='$Wrinkle' OR";
	$sqlCmd=$sqlCmd." Prob_Skin3='$bodycolornotRegularly' OR Prob_Skin3='$Acneonbody' OR Prob_Skin3='$HandFoot' OR";
	$sqlCmd=$sqlCmd." Prob_Skin4='$Acneonface' OR  Prob_Skin4='$Pimple' OR Prob_Skin4='$Pores' OR";
	$sqlCmd=$sqlCmd." Prob_Skin4='$Melasma' OR Prob_Skin4='$SkincolornotRegularly' OR Prob_Skin4='$Wrinkle' OR";
	$sqlCmd=$sqlCmd." Prob_Skin4='$bodycolornotRegularly' OR Prob_Skin4='$Acneonbody' OR Prob_Skin4='$HandFoot' OR";
	$sqlCmd=$sqlCmd." Prob_Skin5='$Acneonface' OR  Prob_Skin5='$Pimple' OR Prob_Skin5='$Pores' OR";
	$sqlCmd=$sqlCmd." Prob_Skin5='$Melasma' OR Prob_Skin5='$SkincolornotRegularly' OR Prob_Skin5='$Wrinkle' OR";
	$sqlCmd=$sqlCmd." Prob_Skin5='$bodycolornotRegularly' OR Prob_Skin5='$Acneonbody' OR Prob_Skin5='$HandFoot' OR";
	$sqlCmd=$sqlCmd." Prob_Skin6='$Acneonface' OR  Prob_Skin6='$Pimple' OR Prob_Skin6='$Pores' OR";
	$sqlCmd=$sqlCmd." Prob_Skin6='$Melasma' OR Prob_Skin6='$SkincolornotRegularly' OR Prob_Skin6='$Wrinkle' OR";
	$sqlCmd=$sqlCmd." Prob_Skin6='$bodycolornotRegularly' OR Prob_Skin6='$Acneonbody' OR Prob_Skin6='$HandFoot')";
	$result = mysql_query($sqlCmd, $conn) or die(mysql_error());
	if(mysql_num_rows($result) > 0){
		while($row=mysql_fetch_array($result)){
			//วนลูปดึงข้อมูลผลิตภัณฑ์ที่เกี่ยวข้องกับการวิเคราะห์ขึ้นมาแสดงให้ลูกค้าดู
			$Spa_Face=$row['Spa_Face'];
			$Spa_face2=$row['Spa_face2'];
			$Spa_Body=$row['Spa_Body'];
			$Spa_body2=$row['Spa_body2'];
			$Spa_Wax=$row['Spa_Wax'];
			$Spa_Wax2=$row['Spa_Wax2'];
			$Spa_Ionto_fono=$row['Spa_Ionto_fono'];
			$Spa_Ionto_fono2=$row['Spa_Ionto_fono2'];
			$Spa_Base_Cream=$row['Spa_Base_Cream'];
			$Spa_Base_Cream2=$row['Spa_Base_Cream2'];
			$showResult="<strong>รายการผลิตภัณฑ์</strong><br>" ;
			mysql_query("SET NAMES tis620",$conn);
            $c=0;//ตัวแปรเก็บว่ามีผลิตภัณฑ์ที่ต้องใช้ร่วมมากกว่าหนึ่งอย่าง
			
			//แมพรายการที่ได้จาก Weka Data Mining กับตารางข้อมุลภาษาไทย Suggest
			if(!empty($Spa_Face)){
				$Spa_Face=trim($Spa_Face);
				$sqlCmd="SELECT * FROM  suggest WHERE (Suggest='$Spa_Face')";
				$result = mysql_query($sqlCmd, $conn) or die(mysql_error());
				$row=mysql_fetch_array($result);
				//$showResult=$showResult."- ". $row['Suggest2']."<br> ";
				if(strlen(trim($row['Suggest2']))>0){
						$showResult=$showResult."- ".trim($row['Suggest2'])."<br> ";
				}

				//ค้นหาผลิตภัณฑ์ที่ต้องใช้ร่วมกัน
				$Sql="SELECT * FROM association WHERE product_main='$Spa_Face'";
				$rs=mysql_query($Sql,$conn) or die(mysql_error());
				if(mysql_num_rows($rs) > 0){
					$rows=mysql_fetch_array($rs);
					$asso=trim($rows['product_association']);
					//echo $asso;
					$sqlcmd="SELECT * FROM  suggest WHERE (Suggest='$asso')";
					$_rs_ = mysql_query($sqlcmd, $conn) or die(mysql_error());
					$_row_=mysql_fetch_array($_rs_);
					$showResult2=$showResult2."- ". $_row_['Suggest2']."<br> ";
				}
				$c++;
			 }
			 if(!empty($Spa_face2)){
				 $Spa_face2=trim($Spa_face2);
				$sqlCmd="SELECT * FROM  suggest WHERE (Suggest='$Spa_face2')";
				$result = mysql_query($sqlCmd, $conn) or die(mysql_error());
				$row=mysql_fetch_array($result);
				//$showResult=$showResult."- ".$row['Suggest2']."<br> ";
				if(strlen(trim($row['Suggest2']))>0){
						$showResult=$showResult."- ".trim($row['Suggest2'])."<br> ";
				}
				//ค้นหาผลิตภัณฑ์ที่ต้องใช้ร่วมกัน
				$Sql="SELECT * FROM association WHERE product_main='$Spa_face2'";
				$rs=mysql_query($Sql,$conn) or die(mysql_error());
				if(mysql_num_rows($rs) > 0){
					$rows=mysql_fetch_array($rs);
					$asso=trim($rows['product_association']);
					//echo $asso;
					$sqlcmd="SELECT * FROM  suggest WHERE (Suggest='$asso')";
					$_rs_ = mysql_query($sqlcmd, $conn) or die(mysql_error());
					$_row_=mysql_fetch_array($_rs_);
					$showResult2=$showResult2."- ". $_row_['Suggest2']."<br> ";
				}
				$c++;
			 }
			  if(!empty($Spa_Body)){
				  $Spa_Body=trim($Spa_Body);
				$sqlCmd="SELECT * FROM  suggest WHERE (Suggest='$Spa_Body')";
				$result = mysql_query($sqlCmd, $conn) or die(mysql_error());
				$row=mysql_fetch_array($result);
				//$showResult=$showResult."- ".$row['Suggest2']."<br> ";
				if(strlen(trim($row['Suggest2']))>0){
						$showResult=$showResult."- ".trim($row['Suggest2'])."<br> ";
				}
				//ค้นหาผลิตภัณฑ์ที่ต้องใช้ร่วมกัน
				$Sql="SELECT * FROM association WHERE product_main='$Spa_Body'";
				$rs=mysql_query($Sql,$conn) or die(mysql_error());
				if(mysql_num_rows($rs) > 0){
					$rows=mysql_fetch_array($rs);
					$asso=trim($rows['product_association']);
					//echo $asso;
					$sqlcmd="SELECT * FROM  suggest WHERE (Suggest='$asso')";
					$_rs_ = mysql_query($sqlcmd, $conn) or die(mysql_error());
					$_row_=mysql_fetch_array($_rs_);
					$showResult2=$showResult2."- ". $_row_['Suggest2']."<br> ";
				}
				$c++;
			 }
			  if(!empty($Spa_body2)){
				 $Spa_body2=trim($Spa_body2);
				$sqlCmd="SELECT * FROM  suggest WHERE (Suggest='$Spa_body2')";
				$result = mysql_query($sqlCmd, $conn) or die(mysql_error());
				$row=mysql_fetch_array($result);
				//$showResult=$showResult."- ".$row['Suggest2']."<br> ";
				if(strlen(trim($row['Suggest2']))>0){
						$showResult=$showResult."- ".trim($row['Suggest2'])."<br> ";
				}

				//ค้นหาผลิตภัณฑ์ที่ต้องใช้ร่วมกัน
				$Sql="SELECT * FROM association WHERE product_main='$Spa_body2'";
				$rs=mysql_query($Sql,$conn) or die(mysql_error());
				if(mysql_num_rows($rs) > 0){
					$rows=mysql_fetch_array($rs);
					$asso=trim($rows['product_association']);
					//echo $asso;
					$sqlcmd="SELECT * FROM  suggest WHERE (Suggest='$asso')";
					$_rs_ = mysql_query($sqlcmd, $conn) or die(mysql_error());
					$_row_=mysql_fetch_array($_rs_);
					$showResult2=$showResult2."- ". $_row_['Suggest2']."<br> ";
				}
				$c++;
			 }
			  if(!empty($Spa_Wax)){
				$Spa_Wax=trim($Spa_Wax);
				$sqlCmd="SELECT * FROM  suggest WHERE (Suggest='$Spa_Wax')";
				$result = mysql_query($sqlCmd, $conn) or die(mysql_error());
				$row=mysql_fetch_array($result);
				//$showResult=$showResult."- ".$row['Suggest2']."<br> ";
				if(strlen(trim($row['Suggest2']))>0){
						$showResult=$showResult."- ".trim($row['Suggest2'])."<br> ";
				}

				//ค้นหาผลิตภัณฑ์ที่ต้องใช้ร่วมกัน
				$Sql="SELECT * FROM association WHERE product_main='$Spa_Wax'";
				$rs=mysql_query($Sql,$conn) or die(mysql_error());
				if(mysql_num_rows($rs) > 0){
					$rows=mysql_fetch_array($rs);
					$asso=trim($rows['product_association']);
					$sqlcmd="SELECT * FROM  suggest WHERE (Suggest='$asso')";
					$_rs_ = mysql_query($sqlcmd, $conn) or die(mysql_error());
					$_row_=mysql_fetch_array($_rs_);
					$showResult2=$showResult2."- ". $_row_['Suggest2']."<br> ";
				}
				$c++;
			 }
			  if(!empty($Spa_Wax2)){
				$Spa_Wax2=trim($Spa_Wax2);
				$sqlCmd="SELECT * FROM  suggest WHERE (Suggest='$Spa_Wax2')";
				$result = mysql_query($sqlCmd, $conn) or die(mysql_error());
				$row=mysql_fetch_array($result);
				//$showResult=$showResult."- ".$row['Suggest2']."<br> ";
				if(strlen(trim($row['Suggest2']))>0){
						$showResult=$showResult."- ".trim($row['Suggest2'])."<br> ";
				}
				//ค้นหาผลิตภัณฑ์ที่ต้องใช้ร่วมกัน
				$Sql="SELECT * FROM association WHERE product_main='$Spa_Wax2'";
				$rs=mysql_query($Sql,$conn) or die(mysql_error());
				if(mysql_num_rows($rs) > 0){
					$rows=mysql_fetch_array($rs);
					$asso=trim($rows['product_association']);
					$sqlcmd="SELECT * FROM  suggest WHERE (Suggest='$asso')";
					$_rs_ = mysql_query($sqlcmd, $conn) or die(mysql_error());
					$_row_=mysql_fetch_array($_rs_);
					$showResult2=$showResult2."- ". $_row_['Suggest2']."<br> ";
				}
				$c++;
			 }
			  if(!empty($Spa_lonto_fono)){
				$Spa_lonto_fono=trim($Spa_lonto_fono);
				$sqlCmd="SELECT * FROM  suggest WHERE (Suggest='$Spa_lonto_fono')";
				$result = mysql_query($sqlCmd, $conn) or die(mysql_error());
				$row=mysql_fetch_array($result);
				//$showResult=$showResult."- ".$row['Suggest2']."<br> ";
				if(strlen(trim($row['Suggest2']))>0){
						$showResult=$showResult."- ".trim($row['Suggest2'])."<br> ";
				}
				//ค้นหาผลิตภัณฑ์ที่ต้องใช้ร่วมกัน
				$Sql="SELECT * FROM association WHERE product_main='$Spa_Ionto_fono'";
				$rs=mysql_query($Sql,$conn) or die(mysql_error());
				if(mysql_num_rows($rs) > 0){
					$rows=trim(mysql_fetch_array($rs));
					$asso=$rows['product_association'];
					$sqlcmd="SELECT * FROM  suggest WHERE (Suggest='$asso')";
					$_rs_ = mysql_query($sqlcmd, $conn) or die(mysql_error());
					$_row_=mysql_fetch_array($_rs_);
					$showResult2=$showResult2."- ". $_row_['Suggest2']."<br> ";
				}
				$c++;
			 }
			   if(!empty($Spa_Ionto_fono2)){
				$Spa_Ionto_fono2=trim($Spa_Ionto_fono2);
				$sqlCmd="SELECT * FROM  suggest WHERE (Suggest='$Spa_Ionto_fono2')";
				$result = mysql_query($sqlCmd, $conn) or die(mysql_error());
				$row=mysql_fetch_array($result);
				//$showResult=$showResult."- ".$row['Suggest2']."<br> ";
				if(strlen(trim($row['Suggest2']))>0){
						$showResult=$showResult."- ".trim($row['Suggest2'])."<br> ";
				}
				//ค้นหาผลิตภัณฑ์ที่ต้องใช้ร่วมกัน
				$Sql="SELECT * FROM association WHERE product_main='$Spa_Ionto_fono2'";
				$rs=mysql_query($Sql,$conn) or die(mysql_error());
				if(mysql_num_rows($rs) > 0){
					$rows=mysql_fetch_array($rs);
					$asso=trim($rows['product_association']);
					$sqlcmd="SELECT * FROM  suggest WHERE (Suggest='$asso')";
					$_rs_ = mysql_query($sqlcmd, $conn) or die(mysql_error());
					$_row_=mysql_fetch_array($_rs_);
					$showResult2=$showResult2."- ". $_row_['Suggest2']."<br> ";
				}
				$c++;
			 }
			   if(!empty($Spa_Base_Cream)){
				 $Spa_Base_Cream=trim($Spa_Base_Cream);
				$sqlCmd="SELECT * FROM  suggest WHERE (Suggest='$Spa_Base_Cream')";
				$result = mysql_query($sqlCmd, $conn) or die(mysql_error());
				$row=mysql_fetch_array($result);
				//$showResult=$showResult."- ".$row['Suggest2']."<br> ";
				if(strlen(trim($row['Suggest2']))>0){
						$showResult=$showResult."- ".trim($row['Suggest2'])."<br> ";
				}
				//ค้นหาผลิตภัณฑ์ที่ต้องใช้ร่วมกัน
				$Sql="SELECT * FROM association WHERE product_main='$Spa_Base_Cream'";
				$rs=mysql_query($Sql,$conn) or die(mysql_error());
				if(mysql_num_rows($rs) > 0){
					$rows=mysql_fetch_array($rs);
					$asso=trim($rows['product_association']);
					$sqlcmd="SELECT * FROM  suggest WHERE (Suggest='$asso')";
					$_rs_ = mysql_query($sqlcmd, $conn) or die(mysql_error());
					$_row_=mysql_fetch_array($_rs_);
					$showResult2=$showResult2."- ". $_row_['Suggest2']."<br> ";
				}
				$c++;
			 }
			   if(!empty($Spa_Base_Cream2)){
				 $Spa_Base_Cream2=trim($Spa_Base_Cream2);
				$sqlCmd="SELECT * FROM  suggest WHERE (Suggest='$Spa_Base_Cream2')";
				$result = mysql_query($sqlCmd, $conn) or die(mysql_error());
				$row=mysql_fetch_array($result);
				//$showResult=$showResult."- ".$row['Suggest2']."<br> ";
				if(strlen(trim($row['Suggest2']))>0){
						$showResult=$showResult."- ".trim($row['Suggest2'])."<br> ";
				}
				//ค้นหาผลิตภัณฑ์ที่ต้องใช้ร่วมกัน
				$Sql="SELECT * FROM association WHERE product_main='$Spa_Base_Cream2'";
				$rs=mysql_query($Sql,$conn) or die(mysql_error());
				if(mysql_num_rows($rs) > 0){
					$rows=mysql_fetch_array($rs);
					$asso=trim($rows['product_association']);
					$sqlcmd="SELECT * FROM  suggest WHERE (Suggest='$asso')";
					$_rs_ = mysql_query($sqlcmd, $conn) or die(mysql_error());
					$_row_=mysql_fetch_array($_rs_);
					$showResult2=$showResult2."- ". $_row_['Suggest2']."<br> ";
				}
				$c++;
			 }
		}
		 $getStr=substr($showResult,strripos($showResult, "- <br>"));
		 //echo strlen(trim($getStr));
		 if(strlen(trim(substr($showResult,strripos($showResult,"-"))))==6){
			 $showResult=substr($showResult,0,strripos($showResult,"-")-1);
		 }
		if($c > 1){
			$getStr=substr($showResult,strripos($showResult, "-"));
		}
		 
	}else{
		$showResult="ไม่ผลิตภัณฑ์ที่ตรงกับท่าน";
	}
   echo("<script>");
   echo("alert('ขณะนี้ได้ประมวลผลเรียบร้อยแล้ว');");
   echo("</script>");

?>
      </p>
      <form id="advise" name="advise" method="post" action="">
        <p align="center"><?echo $showResult;?></p>
        <div align="center"></div>
        <p align="center">&nbsp;</p>
        <p align="center"><span class="style66">ผลิตภัณฑ์ควรซื้อคู่กัน</span><span class="style66">เพื่อผลลัพท์ที่ดียิ่งขึ้น</span></p>
        <p align="center"><?echo $showResult2;?></p>
        <p>&nbsp;</p>
        <p>&nbsp;</p>
        <p>&nbsp;</p>
      </form>
      <p align="center">&nbsp;</p>
    </div></td>
  </tr>
</table>
<table width="633" height="24" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
   
  </tr>
</table>
<body Onload="doAdd('1','')">
</body>
</html>
